package lvyou;


import java.util.*;

public class Manage {
    private Map<Visitor, List> map = new HashMap<>();
    private List<Visitor> list = new ArrayList<>();
    private List<Visitor> list1 = new ArrayList<>();

    public boolean enter(int choose) {
        Scanner input = new Scanner(System.in);
        switch (choose) {
            case 1:
                String index;
                System.out.println("请输入出行日期(如:20170908)");
                String data = input.next();
                System.out.println("请输入出行人手机号码");
                String phone = null;
                String name = null;
                int age = 0;
                double prise = 0;
                try {
                    phone = input.next();
                    if (phone.length() != 11) {
                        throw new Exception();
                    }
                } catch (Exception e) {
                    System.out.println("手机输入不正确");
                    return true;
                }
                System.out.println("***添加出行人信息***");
                do {
                    System.out.println("1.成人\t2.儿童(1.2米以下)\t3.老人(65岁以上)请选择类型:");
                    int choose1 = input.nextInt();
                    if (choose1 == 1) {
                        System.out.println("请输入名字:");
                        name = input.next();
                        System.out.println("请输入年龄:");
                        age = input.nextInt();
                        Visitor v1 = new Visitor(age, name, 2000);
                        v1.show();
                        list.add(v1);
                    } else if (choose1 == 2) {
                        Visitor v2;
                        System.out.println("请输入名字:");
                        name = input.next();
                        System.out.println("请输入年龄:");
                        age = input.nextInt();
                        System.out.println("是否占床(1.占床\t2.不占床)");
                        int index1 = input.nextInt();
                        if (index1 == 1) {
                            v2 = new VisitorS(age, name, 30,true);
                        }else {
                            v2 = new VisitorS(age, name, 0,false);
                        }
                        VisitorS s = (VisitorS)v2;
                        s.show();
                        list.add(v2);
                    } else if (choose1 == 3) {
                        System.out.println("请输入名字:");
                        name = input.next();
                        System.out.println("请输入年龄:");
                        age = input.nextInt();
                        if (age < 65) {
                            System.out.println("年龄出错");
                            System.exit(1);
                        }
                        Visitor v3 = new VisitorO(age, name, 1000);
                        v3.show();
                        list.add(v3);
                    }
                    map.put(new Visitor(phone, data), list);
                    System.out.println("需要继续添加吗(y/n)?");
                    index = input.next();
                } while (index.equals("y") || index.equals("Y"));
                break;
            case 2:
                Set<Visitor> set = map.keySet();
                for (Visitor visitor : set) {
                    System.out.println("出发日期:" + visitor.getData());
                    System.out.println("出行人联系电话:" + visitor.getPhone());
                    System.out.println("详细信息:");
                    System.out.println("姓名\t\t年龄\t儿童是否占床\t金额");
                    for (Object o : map.get(visitor)) {
                        Visitor v = (Visitor)o;
                        if(v.getPrise()==30){
                            System.out.println(v.getName()+"\t"+v.getAge()+"\t\t"+"是"+"\t\t"+v.getPrise());
                        }else {
                            System.out.println(v.getName() + "\t" + v.getAge() + "\t" + " \t\t" + "\t" + v.getPrise());
                        }
                    }
                    break;
                }
                break;
            case 3:
                String phone3;
                String data3;
                System.out.println("请输入新的出行日期:");
                data3 = input.next();
                System.out.println("请输入新的联系电话:");
                try {
                    phone3 = input.next();
                    if(phone3.length()!=11){
                        throw new Exception();
                    }
                } catch (Exception e) {
                    System.out.println("手机输入不正确");
                    return true;
                }
                Set set3 = map.keySet();
                for (Object o : set3) {
                    list1 = map.remove(o);
                    break;
                }
                map.put(new Visitor(phone3,data3),list1);
                System.out.println("替换成功");
                break;
            case 4:
                boolean index4=false;
                System.out.println("输入名字:");
                String name4 = input.next();
                Set<Visitor> set4 = map.keySet();
                for (Visitor visitor : set4) {
                    for (Object o : map.get(visitor)) {
                        Visitor v = (Visitor)o;
                        if(v.getName().equals(name4)){
                            map.get(visitor).remove(o);
                            System.out.println("删除成功");
                            index4=true;
                            break;
                        }
                    }
                }
                if(!index4){
                    System.out.println("查无此人");
                }
                break;
            case 5:
                System.out.println("解放碑------>洪崖洞----->朝天门");
                break;
            case 6:
                System.out.println("感谢使用");
                return false;
            default:
                System.out.println("输入出错");
                break;
        }
        return true;
    }
}
